﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Logic.Utils
{
    public class SystemUtils
    {
		//public static void SaveImage(string path, Stream stream)
		//{
		//    using (var image = System.Drawing.Image.FromStream(stream))
		//    {
		//        var resizedImage = Lehavi.Imaging.ImageResizer.CropBitmap(image, 125, 125);

		//        resizedImage.Save(path);
		//    }
		//}

		public static DateTime? ConvertToNullableDateTime(string str)
		{
			DateTime temp;

			if (DateTime.TryParse(str, out temp))
				return temp;
			return null;
		}

    }

	public enum ServiceResultOptions
	{
		ServiceValidationFailure,       // Occurs when the request did not comply to the services authentication
		Success,                        // Occurs when the operation succeeded
		SystemException,                // Occurs when a system exception had been thrown during the execution of the requested service method
		ValidationFailure,              // Occurs when a validation performed in the service method returned a validation failure response
		OperationFailure,               // Occurs when the operation did not succeed
		IncorrectParameters             // Occurs when the parameter passed to the service method where incorrect or incomplete
	}

	public class ServiceResponse
	{
		public ServiceResultOptions ResultOption { get; set; }
		public string Message { get; set; }

		public ServiceResponse()
		{
			this.ResultOption = ServiceResultOptions.SystemException;
		}

		public virtual void SetException(Exception ex)
		{
			this.Message = ex.Message;
			this.ResultOption = ServiceResultOptions.SystemException;
		}

		public virtual void SetSuccess()
		{
			this.ResultOption = ServiceResultOptions.Success;
		}
	}

	public class BooleanServiceResponse : ServiceResponse
	{
		public bool Success { get; set; }
	}

	public class ContentServiceResponse<T> : ServiceResponse
	{
		public T Content { get; set; }
	}

	
}
